package com.yzj.micro.demo.all.controller;

import com.yzj.demo.common.pojo.vo.CartVO;
import com.yzj.demo.common.response.JsonResult;
import com.yzj.micro.demo.all.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    @PostMapping("add")
    public JsonResult<Boolean> saveCart(
            String userId,
            String productCode,
            Integer count
    ) {
        cartService.saveCart(userId,productCode,count);
        return JsonResult.ok(true);
    }

    @GetMapping("list_my")
    public JsonResult<List<CartVO>> getList(
            String userId
    )
    {
        return JsonResult.ok(cartService.getUserCart(userId));
    }
}
